import { useRef } from 'react';
import { getUerInfo } from '@/common/index';
// import { AUTHORITY } from '@/common/const';

export const useAuth = ({ routes }) => {
  const route = routes.find((item) => item.path === window.location.pathname) || {};
  const { authority = [] } = route;

  // 这里是登录权限验证
  const isLogin = useRef(
    (() => {
      const userInfo = getUerInfo();
      // if (authority.indexOf(AUTHORITY.NOLOGIN) >= 0) {
      //   return true;
      // }
      return !!userInfo;
    })(),
  );
  return { isLogin: isLogin.current };
};
